page.pageInit = function(){
  //初始化grid
  GirdCtr.gridInit();
  GirdCtr.buttonBind()
}

//grid控制器
var GirdCtr =  $.extend({},defaultGridConFig,{
   gridInit: function(){
	 var _this = this;
	//创建jqGrid组件
	_this.grid = $("#mainGrid").jqGrid({
		 			datatype: "json",
		 			url : contextPath+'/depot/in/query.htm',//组件创建完成之后请求数据的url
					datatype : "json",//请求数据返回的类型。可选json,xml,txt
					colModel : [ //jqGrid每一列的配置信息。包括名字，索引，宽度,对齐方式.....
					             {label:"主键", name : "id",sortable:false,hidden:true,key:true},
					             {label:"入库单号", name : 'inOutNo',sortable:false,width : 220,align : "center"}, 
					             {label:"仓库", name : 'warchouseId',sortable:false,width : 220,align : "center",edittype:"select",formatter:'select', editoptions:{value:systemDict.toString(_Warehouse)}},  
					             {label:"入库类型", name : 'inOutType',sortable:false,width : 120,align : "center",edittype:"select",formatter:'select', editoptions:{value:systemDict.toString(_InType)}}, 
					             {label:"状态", name : 'inOutStatus',sortable:false,width : 80,align : "center",edittype:"select",formatter:'select', editoptions:{value:systemDict.toString(_InOutStatus)}}, 
					             {label:"入库时间", name : 'inOutTime',sortable:false,width : 140,align : "center",formatter:DatFormatter},
					             {label:"创建时间", name : 'createTime',sortable:false,width : 140,align : "center",formatter:DatFormatter}
					             ],
		            shrinkToFit:false,   
		            autoScroll: true, 
					rowNum : 10,//一页显示多少条
					rowList : [ 10, 20, 30 ],//可供用户选择一页显示多少条
					rownumWidth: 20, //设置显示序号的宽度，默认为25  
					pager : '#mainGridPager',//表格页脚的占位符(一般是div)的id
					sortname : 'create_Time',//初始化的时候排序的字段
					sortorder : "asc",//排序方式,可选desc,asc
					mtype : "post",//向后台请求数据的ajax的类型。可选post,get
					width:page.window.grid.width,
					height:page.window.grid.height
				});
		/*创建jqGrid的操作按钮容器*/
		/*可以控制界面上增删改查的按钮是否显示*/
		$("#mainGrid").jqGrid('navGrid', '#mainGridPager', {edit:false,add:false,del:false,search:false,view:false,refresh:false});
	},
	buttonBind:function(){//控制按钮初始化
	  var _this = this;
	  $("#addBtn").bind("click",function(){_this.event.doAdd(_this,this)});
	  $("#editBtn").bind("click",function(){_this.event.doEdit(_this,this)});
	  $("#deleteBtn").bind("click",function(){_this.event.doDelete(_this,this)});
	  $("#detailBtn").bind("click",function(){_this.event.doDetail(_this,this)});
	  $("#applyBtn").bind("click",function(){_this.event.doApply(_this,this)});
	  $("#inBtn").bind("click",function(){_this.event.doIn(_this,this)});
	 
	}, 
	event:{//事件
	  doAdd:function(_this,btn){
		  var menuId = $(btn).attr("menuId");
			  var params = {menuId:menuId}
			  showWindow("创建收货单",contextPath+"/depot/in/addView.htm",params,function(){
				  GirdCtr.reLoad();
			  },true);
	  },
	  doEdit:function(_this,btn){//修改
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {menuId:menuId,id:node.id}
			  showWindow("修改收货单",contextPath+"/depot/in/editView.htm",params,function(){
				  GirdCtr.reLoad();
			  },true);
		  }else{
			  layer.msg("选择需要修改的数据");
		  }
	  },
	  doDetail:function(_this,btn){//修改
		  var menuId = $(btn).attr("menuId");
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  var params = {menuId:menuId,id:node.id}
			  showWindow("查看收货单",contextPath+"/depot/in/detailView.htm",params,function(){
				  
			  },true);
		  }else{
			  layer.msg("选择需要查看的数据");
		  }
	  },
	  doApply:function(_this,btn){//修改
		  var node = GirdCtr.getSelectRowData();
		  if(node){
			  showIframeWindow("用户选择",contextPath+"/depot/activiti/userAndActView.htm?actKey=storeIn",null,function(act,userIds){
				  var params ={
						  actKey:'storeIn',
						  userIds: userIds,
						  deployId:act.deploymentId,
						  defId:act.defid,
						  inOutNo:node.inOutNo
				  };
				  $.dataPost(contextPath+'/depot/in/apply.htm',params,function(result){
					  if(result.success){
						  GirdCtr.reLoad();
					  }else{
						  layer.msg(result.msg); 
					  }
				  });
				  });
		  }else{
			  layer.msg("选择需要查看的数据");
		  }
	  },doIn:function(_this,btn){//入库
		  var id = _this.grid.jqGrid('getGridParam','selrow');
		  if(id){
			  $.dataPost(contextPath+'/depot/in/in.htm',{id:id},function(result){
				  if(result.success){
					  GirdCtr.reLoad();
				  }else{
					  layer.msg(result.msg); 
				  }
			  });
		  }else{
			  layer.msg("选择需要查看的数据");
		  }
	  },
	  doDelete:function(_this,btn){//删除
		  var id = _this.grid.jqGrid('getGridParam','selrow');
		  if(id){
			 var laIndex = layer.confirm('确定要删除该数据吗？', {
				  btn: ['确定','取消'] //按钮
				}, function(){
					_this.event.gridDoDelete(id,_this);
					layer.close(laIndex);
				});
		  }else{
			  layer.msg("请选择删除的数据.");
		  }
	  },gridDoDelete:function(id,_this){
		  $.dataPost(contextPath+'/depot/in/delete.htm',{id:id},function(result){
			  if(result.success){
				  GirdCtr.reLoad();
			  }else{
				  layer.msg(result.msg); 
			  }
		  });
	  }
	}
});

